package com.von.nhcf.controller;

import com.von.nhcf.entity.vo.AddressVO;
import com.von.nhcf.entity.vo.OrderProjectVO;
import com.von.nhcf.entity.vo.OrderVO;
import com.von.nhcf.service.MysqlOrderService;
import com.von.nhcf.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MysqlOrderController {
    @Autowired
    private MysqlOrderService mysqlOrderService;

    @RequestMapping("/get/order/project/vo/remote")
    ResultEntity<OrderProjectVO> getProjectVORemote(@RequestParam("projectId")Integer projectId,
                                                    @RequestParam("returnId") Integer returnId) {
        try {
            OrderProjectVO orderProjectVO = mysqlOrderService.getOrderProjectVO(projectId, returnId);
            return ResultEntity.successWithData(orderProjectVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failureWithMsg(e.getMessage());
        }
    }

    @RequestMapping("/get/order/address/vo/remote")
    ResultEntity<List<AddressVO>> getAddressVORemote(@RequestParam("memberId") Integer memberId) {
        try {
            List<AddressVO> addressVOList = mysqlOrderService.getAddressVOList(memberId);
            return ResultEntity.successWithData(addressVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failureWithMsg(e.getMessage());
        }
    }
    @RequestMapping("/save/order/address/po/remote")
    void saveAddressRemote(@RequestBody AddressVO addressVO) {
        mysqlOrderService.saveAddressVO(addressVO);
    }
    @RequestMapping("/save/order/vo/remote")
    void saveOrderRemote(@RequestBody OrderVO orderVO){
        mysqlOrderService.saveOrderVO(orderVO);
    }
}
